package cn.jekun.shop.app.action;

import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.log4j.Logger;

import net.sf.json.DateJsonValueProcessor;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import cn.jekun.component.base.bean.ErrorMsg;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.component.base.utils.SqlUtis;
import cn.jekun.component.core.Constants;
import cn.jekun.component.core.Constants.ERP_ORDER_TYPE;
import cn.jekun.component.core.bean.gen.ErpDeliveryAddress;
import cn.jekun.component.core.bean.gen.ErpOrderMessage;
import cn.jekun.component.core.service.gen.ErpDeliveryAddressService;
import cn.jekun.component.core.service.gen.ErpPaymentService;
import cn.jekun.shop.common.service.OrderService;
import cn.jekun.shop.common.service.ShopService;
import cn.jekun.shop.web.bean.ErpOrderItem;
import cn.jekun.shop.web.bean.Order;

/**
 * 订单(app)
 * @author Mr.Dong
 *
 */
@SuppressWarnings("serial")
public class OrderAction extends AppBaseAction{
	@Resource(name = cn.jekun.component.shop.service.OrderService.BEAN_NAME)
	protected cn.jekun.component.shop.service.OrderService commponentorderService;
	@Resource(name = ErpDeliveryAddressService.BEAN_NAME)
	protected ErpDeliveryAddressService addressService;
	@Resource(name = ErpPaymentService.BEAN_NAME)
	protected ErpPaymentService paymentService;
	@Resource(name = OrderService.BEAN_NAME)
	protected OrderService orderService;
	
	@Resource(name = ShopService.BEAN_NAME)
	protected ShopService shopService;
	
	
	private List<ErpOrderItem> orderitemslist = new ArrayList<ErpOrderItem>();
	public List<ErpOrderItem> getOrderitemslist() {
		return orderitemslist;
	}
	public void setOrderitemslist(List<ErpOrderItem> orderitemslist) {
		this.orderitemslist = orderitemslist;
	}
    private Logger logger = Logger.getLogger(OrderAction.class);
	/**
	 * 获取从购物车选择的商品信息(app)
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String getOrderGoods(){

		JSONObject jsonObject = new JSONObject();
		try {

			this.validateSign(getLoginSign(),request.getParameter("cartId"));
			this.validateLoginApp();
			String terminalId = this.request.getParameter("terminalId");
			String cartIds = request.getParameter("cartId"); //cartId、多个用,隔开
			jsonObject = orderService.getOrderGooods(this.getUserId(),cartIds);

			JsonConfig jsonConfig = new JsonConfig();
			jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor("yyyy-MM-dd")); 

			//默认收货地址
			Map map = new HashMap();
			map.put(ErpDeliveryAddress.COL_USER_ID, getUserId());
			map.put(ErpDeliveryAddress.COL_DEF, "1");
			map.put(ErpDeliveryAddress.COL_AVAILABLE, "1");
			SqlUtis.prepareSql(map, SqlUtis.getSQL(map, ErpDeliveryAddress.COL_USER_ID,Types.VARCHAR,SqlUtis.EQ)
					, SqlUtis.getSQL(map, ErpDeliveryAddress.COL_DEF,Types.VARCHAR,SqlUtis.EQ)
					, SqlUtis.getSQL(map, ErpDeliveryAddress.COL_AVAILABLE,Types.VARCHAR,SqlUtis.EQ));
			ErpDeliveryAddress address = addressService.one(map);
			if(StringUtils.isNotBlank(terminalId)){
				jsonObject.put("address", address==null?"[]":JSONArray.fromObject(address, jsonConfig));
				
			}else{
				jsonObject.put("address", address==null?"":JSONArray.fromObject(address, jsonConfig));
			}
			map.put(ErpDeliveryAddress.COL_DEF, "0");
			SqlUtis.prepareSql(map, SqlUtis.getSQL(map, ErpDeliveryAddress.COL_USER_ID,Types.VARCHAR,SqlUtis.EQ)
					, SqlUtis.getSQL(map, ErpDeliveryAddress.COL_DEF,Types.VARCHAR,SqlUtis.EQ)
					, SqlUtis.getSQL(map, ErpDeliveryAddress.COL_AVAILABLE,Types.VARCHAR,SqlUtis.EQ));
			List<ErpDeliveryAddress> tempList = addressService.list(map);
			if(tempList!=null){
				jsonObject.put("undef", tempList.size());
			}else{
				jsonObject.put("undef", "0");
			}
		} catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}


	/**
	 * 确认订单(app)
	 * @return
	 */
	public String addOrder(){
		JSONObject jsonObject = new JSONObject();
		try {

			String shipTime =request.getParameter("shipTime"); 
			String userId = request.getParameter("userId");
			String addressId = request.getParameter("addressId");
			String paymentId = request.getParameter("paymentId");
			String deliveryId = request.getParameter("deliveryId");//配送方式
//			String deliveryId = "1";//配送方式（暂时默认是商家配送）
			String jsonString = request.getParameter("message");//订单留言(app)
			String terminalId = request.getParameter("terminalId");//手机的唯一标识
			String model = request.getParameter("model");//机器的型号+“_”+系统版本
			List<ErpOrderMessage> orderMessagelist = null;//订单留言(web)
			String orderTypeId = ERP_ORDER_TYPE.APP;//手机下单
			
			if(StringUtils.isBlank(deliveryId)){
				this.validateSign(getLoginSign(),userId,addressId,shipTime,paymentId);
				deliveryId = "1";
			}else{
				this.validateSign(getLoginSign(),userId,addressId,shipTime,paymentId,deliveryId);
			}
			
			//验证是否登录
			this.validateLoginApp();
			String orderStatusId ="";
			if(Constants.ERP_PAYMENT.PAYMENT_CASH_ON_DELIVERY.equals(paymentId)){ //货到付款
				orderStatusId =Constants.ERP_ORDER_STATUS.ORDER; //待发货
			}
			if(Constants.ERP_PAYMENT.PAYMENT_ONLINE.equals(paymentId)){ //在线支付
				orderStatusId =Constants.ERP_ORDER_STATUS.PAY; //待付款
			}
			
			logger.info("==================jsonString ="+jsonString+"=============");
			
			jsonObject = orderService.addOrder(shipTime, addressId, userId, paymentId, orderStatusId, orderTypeId, this.orderitemslist, jsonString, orderMessagelist,this.getIp(),terminalId,model,deliveryId);
			
			this.logService.addMallLog(userId, 
					this.getBrowser(), this.getIp(), "手机下单成功，消费金额，¥"+jsonObject.get("totalMoney"));//记录操作日志
		} catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
			this.logService.addMallLog(request.getParameter("userId"), 
					this.getBrowser(), this.getIp(), "手机下单失败，原因，"+jsonObject.get("message"));//记录操作日志
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);	
	}

	/**
	 * 取消订单(app)
	 * @return
	 * @deprecated 兼容旧版本ios，请使用processOrder
	 */
	public String cancelOrder(){

		JSONObject jsonObject = new JSONObject();
		String userId = request.getParameter("userId");
		String orderId = request.getParameter("orderId");
		try {
			this.validateSign(getLoginSign(),userId,orderId);//签名验证
			//验证是否登录
			this.validateLoginApp();
//			jsonObject = orderService.cancelOrder(userId,orderId);
			jsonObject = this.commponentorderService.processOrder(this.getUserId(), orderId, Constants.ERP_ORDER_PROCESS_BY_USER.GO_TO_CANCEL, this.commponentorderService.TYPE_USER,"10",null,null,null);
			this.logService.addMallLog(userId, 
					this.getBrowser(), this.getIp(), "手机取消订单成功,订单代码:"+orderId);//记录操作日志
		} catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
			this.logService.addMallLog(userId,this.getBrowser(), this.getIp(), "手机取消订单失败,订单代码:"+orderId);//记录操作日志
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);	
	}
	/**
	 * 用户操作订单
	 * @return
	 */
	public String processOrder(){
		JSONObject jsonObject = new JSONObject();
		String orderId = this.request.getParameter("orderId");
		String processCode = this.request.getParameter("processCode");
		String reason = this.request.getParameter("reason");
		String fileUrl = this.request.getParameter("fileUrl");
		String content = this.request.getParameter("content");
		String processer = this.request.getParameter("processer");
		String channelId = this.request.getParameter("channelId");
		try {
			this.validateSign(this.getLoginSign(),this.getUserId(),orderId,processCode,reason,fileUrl,content,channelId);
			this.validateLoginApp();
			jsonObject = this.commponentorderService.processOrder(this.getUserId(), orderId, processCode, processer,reason,fileUrl,content,channelId);
			
			String str="";
			//用户处理订单
			if(cn.jekun.component.shop.service.OrderService.TYPE_USER.equals(processer)){
				//1:取消订单(订单状态为待付款)
				if(Constants.ERP_ORDER_PROCESS_BY_USER.GO_TO_CANCEL.equals(processCode)){
					str = "取消订单";
				}
				//2：去支付(获取tn号) //TODO 兼容旧版本，未来版本会删除
				if(Constants.ERP_ORDER_PROCESS_BY_USER.GO_TO_PAY.equals(processCode)){
					str = "支付订单";
				}
				//3：提醒商家发货
				if(Constants.ERP_ORDER_PROCESS_BY_USER.GO_TO_REMIND.equals(processCode)){
					str = "提醒商家发货";
				}
				//4:确认收货
				if(Constants.ERP_ORDER_PROCESS_BY_USER.GO_TO_CONFIRM.equals(processCode)){
					str = "确认收货";
				}
				//5：拒绝收货
				if(Constants.ERP_ORDER_PROCESS_BY_USER.GO_TO_REFUSE.equals(processCode)){
					str = "拒绝收货";
				}
				//6：申请客服介入
				if(Constants.ERP_ORDER_PROCESS_BY_USER.GO_TO_APPLY.equals(processCode)){
					str = "申请客服介入";
				}
				
			}else if(cn.jekun.component.shop.service.OrderService.TYPE_SHOP.equals(processer)){
				//商家发货
				if(Constants.ERP_ORDER_PROCESS_BY_SHOP.GO_TO_SEND.equals(processCode)){
					str = "已发货";
				}
				//2：商家取消订单 //TODO 兼容旧版本，未来版本会删除
				if(Constants.ERP_ORDER_PROCESS_BY_SHOP.GO_TO_CANCEL.equals(processCode)){
					str = "已取消";
				}
				//3：提醒用户收货
				if(Constants.ERP_ORDER_PROCESS_BY_SHOP.GO_TO_REMIND.equals(processCode)){
					str = "提醒用户收货";
				}
				//4:完成订单
				if(Constants.ERP_ORDER_PROCESS_BY_SHOP.GO_TO_FINISH.equals(processCode)){
					str = "完成订单";
				}
				//5：申请客服介入
				if(Constants.ERP_ORDER_PROCESS_BY_SHOP.GO_TO_APPLY.equals(processCode)){
					str = "申请客服介入";
				}
				
			}
			
			this.logService.addMallLog(this.getUserId(),this.getBrowser(), this.getIp(), "手机用户处理订单"+orderId+":"+str);//记录操作日志
		} catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);	
	}

	/**
	 * 获取商家订单列表(app)
	 * @param shopId
	 * @return
	 */
	public String getOrderByShopId(){

		JSONObject jsonObject = new JSONObject();
		try {

			String days = this.request.getParameter("days");//<=天数
			String statusId = this.request.getParameter("statusId");

			this.validateSign(getLoginSign(),request.getParameter("userId"));//签名验证
			//验证是否登录
			this.validateLoginApp();

			Date endDate = null;
			try {
				int d = Integer.parseInt(days);
				endDate = DateUtils.addDays(new Date(System.currentTimeMillis()), d*-1);
			} catch (Exception e) {
			}

			jsonObject = this.orderService.getOrderByShopId(request.getParameter("pageSize"),
					request.getParameter("currentPage"), this.getSessionUser().getShopId(),null,statusId,endDate,true);
		} catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}

	/**
	 * 商家处理订单(app,订单处理)
	 * @return
	 */
	/*public String processOrder(){

		JSONObject jsonObject = new JSONObject();
		//基本验证
		if(StringUtils.isBlank(request.getParameter("orderId"))){
			jsonObject.put("code",Constants.ERRORS.VALIDATE_ERROR_CODE);
			jsonObject.put("message","订单代码不能为空");
		}
		if(StringUtils.isBlank(request.getParameter("type"))){

			jsonObject.put("code",Constants.ERRORS.VALIDATE_ERROR_CODE);
			jsonObject.put("message","操作类型不能为空");
		}

		this.validateSign(getLoginSign(),request.getParameter("userId")
				,request.getParameter("orderId"),request.getParameter("type"));//签名验证
		//验证是否登录
		this.validateLoginApp();

		try{
			if(Constants.ERP_ORDER_STATUS.SHIPPING.equals(request.getParameter("type"))){//发货
				this.commponentorderService.shippingOrderByShop(request.getParameter("userId")
						, request.getParameter("orderId"),null);
				jsonObject.put("type", Constants.ERP_ORDER_STATUS.SHIPPING);
				jsonObject.put("code","1");
				jsonObject.put("message","调用成功");
				this.logService.addMallLog(request.getParameter("userId"), 
						null, null, "商家手机处理订单(发货)成功,订单代码:"+request.getParameter("orderId"));//记录操作日志
			}else if(Constants.ERP_ORDER_STATUS.CLOSED.equals(request.getParameter("type"))){//取消
				this.commponentorderService.cancelOrderByShop(request.getParameter("userId")
						, request.getParameter("orderId"),null);
				jsonObject.put("type", Constants.ERP_ORDER_STATUS.CLOSED);
				jsonObject.put("code","1");
				jsonObject.put("message","调用成功");
				this.logService.addMallLog(request.getParameter("userId"), 
						null, null, "商家手机处理订单(取消/关闭)成功,订单代码:"+request.getParameter("orderId"));//记录操作日志
			}else if(Constants.ERP_ORDER_STATUS.OK.equals(request.getParameter("type"))){//完成
				this.commponentorderService.finishOrderByShop(request.getParameter("userId")
						, request.getParameter("orderId"),null);
				jsonObject.put("type", Constants.ERP_ORDER_STATUS.OK);
				jsonObject.put("code","1");
				jsonObject.put("message","调用成功");
				this.logService.addMallLog(request.getParameter("userId"), 
						null, null, "商家手机处理订单(完成)成功,订单代码:"+request.getParameter("orderId"));//记录操作日志
			}else{
				jsonObject.put("code",Constants.ERRORS.VALIDATE_ERROR_CODE);
				jsonObject.put("message","操作类型非法");
				this.logService.addMallLog(request.getParameter("userId"), 
						null, null, "商家手机处理订单失败,订单代码:"+request.getParameter("orderId"));//记录操作日志
			}

		} catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
			this.logService.addMallLog(request.getParameter("userId"), 
					null, null, "商家手机处理订单失败,订单代码:"+request.getParameter("orderId")+",原因:"+e.getErrorMsg());//记录操作日志
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);

	}*/

	/**
	 * 获取我的订单(app)
	 * @return
	 */
	public String getMyOrderGoods(){

		JSONObject jsonObject = new JSONObject();

		try {

			this.validateSign(getLoginSign(),request.getParameter("userId"));//签名验证
			//验证是否登录
			this.validateLoginApp();

			String days = this.request.getParameter("days");//<=天数
			String statusId = this.request.getParameter("statusId");

			Date endDate = null;
			try {
				int d = Integer.parseInt(days);
				endDate = DateUtils.addDays(new Date(System.currentTimeMillis()), d*-1);
			} catch (Exception e) {
			}
			jsonObject = orderService.getOrderByShopId(request.getParameter("pageSize"),
					request.getParameter("currentPage"), null, request.getParameter("userId"), statusId, endDate,false);
		} catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);	
	}

	/**
	 * 获取订单详情(app)
	 * @return
	 */
	public String getOrder(){
		JSONObject jsonObject = null;

		try {
			String orderId = request.getParameter("orderId");//orderId

			this.validateSign(getLoginSign(),orderId);//签名验证
			//验证是否登录
			this.validateLoginApp();

			jsonObject = this.orderService.getOrder(orderId);

		} catch (BusinessException e) {
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);// 输出
	}

	/**
	 * 推送支付消息到终端
	 * @return
	 */
	public String pushOrderByPayNo(){

		JSONObject jsonObject = null;

		try {

			String payNo = request.getParameter("payNo");

			this.validateSign(getLoginSign(),payNo);//签名验证
			//验证是否登录
			this.validateLoginApp();

			jsonObject = this.orderService.pushOrderByPayNo(payNo);

		} catch (BusinessException e) {
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);// 输出
	}

//	/**
//	 * 推送订单打印消息到终端
//	 * @return
//	 */
//	public String pushOrderPrintByOrderId(){
//
//		JSONObject jsonObject = null;
//
//		try {
//
//			String orderId = request.getParameter("orderId");
//			this.validateSign(getLoginSign(),orderId);//签名验证
//			//验证是否登录
//			this.validateLoginApp();
//			jsonObject = this.orderService.pushOrderPrintByOrderId(orderId);
//
//		} catch (BusinessException e) {
//			jsonObject = JSONObject.fromObject(e.getErrorMsg());
//		} catch (Exception e) {
//			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
//			e.printStackTrace();
//		}
//		return this.writeJson(jsonObject);// 输出
//	}


	/**
	 * 订单追踪
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public String getOrderLogs(){

		JSONObject jsonObject = new JSONObject();

		if(StringUtils.isBlank(request.getParameter("orderId"))){
			jsonObject.put("code", Constants.ERRORS.VALIDATE_ERROR_CODE);
			jsonObject.put("message", "订单代码不能为空");
		}else{
			try {
				this.validateSign(getLoginSign(),request.getParameter("orderId"));//签名验证
				//验证是否登录
				this.validateLoginApp();
				formMap.put("orderId", request.getParameter("orderId"));
				//订单追踪
				List<Order> orderlog = this.orderService.list(this.orderService.getStatementName("selectOrderLog"),formMap);
				jsonObject.put("orderlog", orderlog);
				jsonObject.put("code", "1");
				jsonObject.put("message", "调用成功");
			} catch (BusinessException e) {
				jsonObject = JSONObject.fromObject(e.getErrorMsg());
			} catch (Exception e) {
				jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
				e.printStackTrace();
			}
		}
		return this.writeJson(jsonObject);// 输出
	}
	
	/**
	 * 获取支付方式
	 * @return
	 */
	public String getOrderPayMentType(){

		JSONObject jsonObject = new JSONObject();
		try {
			String shopIds = this.request.getParameter("shopids");//商家id字符串已逗号分开
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),this.getUserId(),shopIds);
			jsonObject = this.shopService.getPaymentByShopId(shopIds);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 * 获取商家配送方式
	 * @return
	 */
	public String getShopDeliveryType(){
		JSONObject jsonObject = new JSONObject();
		try {
			String shopId = this.request.getParameter("shopId");
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),this.getUserId(),shopId);
			jsonObject = this.shopService.getShopDeliveryType(shopId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	
	/**
	 * 原因列表
	 * @return
	 */
	public String reasonList(){
		JSONObject jsonObject = new JSONObject();
		try {
			logger.info("=========================OrderAction reasonList begin=====================================");
			String orderId = this.request.getParameter("orderId");//订单状态
			String processCode = this.request.getParameter("processCode");//操作编码
			String person = this.request.getParameter("person");//操作用户类型
			String userId = this.request.getParameter("userId");
			
			String sourceTxt = "orderId = " + orderId+": processCode = " +processCode+": person = " + person+": userId =" +userId;
			logger.info("=============================终端上送的参数:"+sourceTxt+"=======================================================");

			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),userId,person,processCode,orderId);
		
			jsonObject = this.commponentorderService.reasonList(this.getUserId(), processCode, person,orderId);
		} catch (BusinessException e) {
		jsonObject = JSONObject.fromObject(e.getErrorMsg());
	} catch (Exception e) {
		jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		e.printStackTrace();
	}
	return this.writeJson(jsonObject);// 输出
	}
	
	/**
	 * 
	* @Title: getOrderMessageByOrderId
	* @Description: 查看訂單的留言
	* @param @return    设定文件
	* @return String    返回类型
	* @throws
	 */
	public String getOrderMessageByOrderId(){
		JSONObject jsonObject = new JSONObject();
		try{
			logger.info("============================OrderAction getOrderMessageByOrderId begin================================");
			//獲取參數
			String orderId = this.request.getParameter("orderId");
			String pageSize = request.getParameter("pageSize");//页大小(默认每页10笔)
			String currentPage = request.getParameter("currentPage");//当前页码(默认第1页)
			String terminalId = this.request.getParameter("terminalId"); //终端代码
			String userId = this.request.getParameter("userId"); //用户代码
			//驗證
			this.validateLoginApp();
			this.validateSign(this.getLoginSign(),terminalId,userId,orderId);
			
			int pageNumber=1,ps=10;
			try{
				pageNumber = Integer.parseInt(currentPage);
			}catch(Exception e){
				pageNumber = 1;
			}
			try{
				ps = Integer.parseInt(pageSize);
			}catch(Exception e){
				ps = 10;
			}
			page.setPageSize(ps);
			page.setPageNumber(pageNumber);
			
			logger.info("======================上传的参数orderId："+orderId+"=========================================");
			jsonObject = this.orderService.getOrderMessageByOrderId(orderId,page);
			jsonObject.put(Constants.Page.PAGE_NUMBER,page.getPageNumber());	
		    jsonObject.put(Constants.Page.PAGE_SIZE,page.getPageSize());	
			jsonObject.put(Constants.Page.TOTAL_COUNT,page.getTotalCount());
			jsonObject.put(Constants.Page.TOTAL_PAGE,page.getPages());
			logger.info("=============================getOrderMessageByOrderId json result="+jsonObject.toString());
			logger.info("*************************Order getOrderMessageByOrderId end*********************************************");
		}catch(BusinessException e){
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}catch(Exception e){
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
		}
		return this.writeJson(jsonObject);
	}

}